<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../node_modules/react/umd/react.development.js"></script>
    <script src="../node_modules/react-dom/umd/react-dom.development.js"></script>
    <script src="../node_modules/babel-standalone/babel.min.js"></script>
    <script src="../node_modules/prop-types/prop-types.js"></script>
</head>

<body>
    <div id="root"></div>
    <script type="text/babel">

        class MyCom extends React.Component {

            /* 写法1 */
            // MyCom.propTypes = xxx
            static propTypes = {
                name: PropTypes.string,
                age: PropTypes.number.isRequired
            }

            // MyCom.defaultProps = xxx
            static defaultProps = {
                name: "【一个默认值】"
            }

            render() {
                return <div>劳资{this.props.name},芳龄{this.props.age}</div>
            }
        }

        /* 写法2 */
        // MyCom.propTypes = {
        //     name: PropTypes.string,
        //     age: PropTypes.number.isRequired
        // }

        // MyCom.defaultProps = {
        //     name: "【一个默认值】"
        // }

        const person = {
            // name: "秦始皇",
            name: -221,
            age: -1
        }

        ReactDOM.render(<MyCom {...person} />, document.querySelector("#root"))
        // ReactDOM.render(<MyCom name={person.name} />, document.querySelector("#root"))
        // ReactDOM.render(<MyCom age={person.age} />, document.querySelector("#root"))

    </script>
</body>

</html>